package com.kaifamiao.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;
import java.util.logging.Logger;

public class RequestLifecycleListener implements ServletRequestListener {

    private Logger logger = Logger.getLogger( this.getClass().getName() );

    // 当请求对象被创建后容器就会调用 requestInitialized 方法
    @Override
    public void requestInitialized( ServletRequestEvent event ) {
        ServletContext application = event.getServletContext();
        HttpServletRequest request = (HttpServletRequest)event.getServletRequest() ;
        logger.info( "已经为[" + request.getRequestURI() + "]创建请求对象" );
    }

    // 当请求对象被销毁后容器就会调用 requestDestroyed 方法
    @Override
    public void requestDestroyed( ServletRequestEvent event ) {
        ServletContext application = event.getServletContext();
        HttpServletRequest request = (HttpServletRequest)event.getServletRequest() ;
        logger.info( "已经为[" + request.getRequestURI() + "]销毁请求对象" );
    }

}
